package com.sskj.givecoin.p.activity;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.sskj.givecoin.MyAppLication;
import com.sskj.givecoin.common.Constants;
import com.sskj.givecoin.m.HttpConfig;
import com.sskj.givecoin.m.bean.HttpData;
import com.sskj.givecoin.m.bean.UsefulCoin;
import com.sskj.givecoin.m.bean.UserInfo;
import com.sskj.givecoin.m.http.JsonCallBack;
import com.sskj.givecoin.p.base.BasePresenter;
import com.sskj.givecoin.utils.MD5Util;
import com.sskj.givecoin.utils.SPUtils;
import com.sskj.givecoin.v.activity.TransferActivity;

/**
 * @author Hey
 * @des
 * @date 2018/8/7 9:24
 */
public class TransferPresenter extends BasePresenter<TransferActivity> {
    public void submitTransfer(String id, String num, String ps) {
        OkGo.<HttpData<String>>post(HttpConfig.BASE_URL + HttpConfig.TRANSFER)
                .params("pwd", MD5Util.md5FiveTime(ps))
                .params("ouid", id)
                .params("price", num)
                .execute(new JsonCallBack<HttpData<String>>(this) {
                    @Override
                    protected void _onSuccess(Response<HttpData<String>> response) {
                        if (response.body().status == 200) {
                            mView.submitSuccess();
                        } else {
                            mView.submitFailure(response.body().msg);
                        }
                    }
                });
    }


    public void getUsefulCoin() {
        OkGo.<HttpData<UsefulCoin>>get(HttpConfig.BASE_URL + HttpConfig.GET_BALANCE)
                .params("type", "0")
                .execute(new JsonCallBack<HttpData<UsefulCoin>>() {
                    @Override
                    protected void _onSuccess(Response<HttpData<UsefulCoin>> response) {
                        if (response.body().status == 200) {
                            mView.setUsefulCoin(response.body().getData());
                        }
                    }
                });
    }


    public void upDateUserInfo(String mobile) {
        OkGo.<HttpData<UserInfo>>post(HttpConfig.BASE_URL + HttpConfig.GET_USER_INFO)
                .params("mobile", mobile)
                .execute(new JsonCallBack<HttpData<UserInfo>>(this, false) {
                    @Override
                    public void _onSuccess(Response<HttpData<UserInfo>> response) {
                        HttpData<UserInfo> httpData = response.body();
                        if (httpData.getStatus() == 200) {
                            mView.setUserInfo(httpData.getData());
                            SPUtils.put(MyAppLication.getApplication(), Constants.SP_IS_SHOP, httpData.getData().is_shop);
                            SPUtils.put(MyAppLication.getApplication(), Constants.SP_REALNAME_STATUS, httpData.getData().getStatus());
                            SPUtils.put(MyAppLication.getApplication(), Constants.SP_REALNAME_STATUS_HIGH, httpData.getData().getAuth_status());
                            SPUtils.put(MyAppLication.getApplication(), Constants.SP_PAY_SIZE, httpData.getData().getPay_list());
                            if (httpData.getData().getRealname() != null) {
                                SPUtils.put(MyAppLication.getApplication(), Constants.SP_REALNAME, httpData.getData().getRealname());
                            }
                            if (httpData.getData().getIdcard() != null) {
                                SPUtils.put(MyAppLication.getApplication(), Constants.SP_IDCORD, httpData.getData().getIdcard());
                            }
                            SPUtils.put(MyAppLication.getApplication(), Constants.SP_JGCODE, httpData.getData().getJigou_code());
                            SPUtils.put(MyAppLication.getApplication(), Constants.SP_USDT, httpData.getData().getUsdt());
                        }
                    }
                });
    }
}
